package com.observer.inner_api;

import java.util.Observable;

/**
 * @ClassName: WeatherData
 * @Author: ZhangYue26
 * @Description: 被观察者对象，实现主java内置API接口
 * @Date: 2020-09-17
 */
public class WeatherData extends Observable {

    private float temperature;//温度
    private float humidity;//湿度
    private float airpressure;//气压

    public WeatherData(){
    }

    /**
      * @Description 通知所有观察者
      * @author ZhangYue26
      * @date 2020/9/17
      * @param []
      * @return void
      **/
    public void notifyAllObserver() {
        super.setChanged();//调用父类方法-修改通知状态
        super.notifyObservers();//通知所有观察者
    }

    /**
      * @Description 被观察者数据发生改变
      * @author ZhangYue26
      * @date 2020/9/17
      * @param [temperature, humidity, airpressure]
      * @return void
      **/
    public void setMeasurements(float temperature,float humidity,float airpressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.airpressure = airpressure;
        notifyAllObserver();//修改后通知观察者
    }

    public float getTemperature() {
        return temperature;
    }

    public float getHumidity() {
        return humidity;
    }

    public float getAirpressure() {
        return airpressure;
    }

}
